/*
 * ModelImpl.h
 *
 *  Created on: 2011/08/07
 *      Author: naoki
 */

#ifndef INCLUDED_NTENGINE_SCENE_MODELIMPL_H
#define INCLUDED_NTENGINE_SCENE_MODELIMPL_H

#include "NTEngine/Math/Vector3.h"
#include "NTEngine/Math/Matrix3x4.h"
#include "NTEngine/Math/Matrix4x4.h"
#include "NTEngine/Math/Function.h"
#include "NTEngine/Base/ReferenceCounter.h"
#include "NTEngine/Graphics/Manager.h"

#include "Scene/src/BatchImpl.h"
#include "Scene/src/ContainerImpl.h"

namespace NTEngine {
using namespace Graphics;
namespace Scene {

class Model::Impl : public ReferenceCounter {
public:
	Impl( Batch::Impl* b ) :
	mBatch( b ),
	mPosition( 0.f, 0.f, 0.f ),
	mAngle( 0.f, 0.f, 0.f ),
	mScale( 1.f, 1.f, 1.f ),
	mColor( 1.f, 1.f, 1.f ),
	mTransparency( 1.f ) {
		mBatch->container()->refer();
	}
	~Impl(){
		Container::Impl* c = mBatch->container();
		if ( c->unref() <= 0 ) {
			SAFE_DELETE( c );
		}
		mBatch = 0;
	}
	void draw(){
		ASSERT( mBatch && "Model::draw() : no Batch specified!" );

		//ワールド行列を作る
		Matrix3x4 w;
		w.setTranslation( mPosition );
		w.rotateY( mAngle.y );
		w.rotateX( mAngle.x );
		w.rotateZ( mAngle.z );
		w.scale( mScale );
		Graphics::Manager().setWorldMatrix( w );
		//描画
		mBatch->draw( mColor, mTransparency );
	}
	Batch::Impl* mBatch;
	Vector3 mPosition;
	Vector3 mAngle;
	Vector3 mScale;
	Vector3 mColor;
	float mTransparency;
};

} //namespace Scene
} //namespace NTEngine

#endif // INCLUDED_NTENGINE_SCENE_MODELIMPL_H
